package general.components;

import general.GameSpeed;
import general.Component;

class SimpleMovable
{

    public inline static var typeid = 5;

    public inline static var scene = 0;
    public inline static var x = 1;
    public inline static var y = 2;
    public inline static var xspeed = 3;
    public inline static var yspeed = 4;

    #if flash9
    public var lasttime : Float;
    public var comp : Component;

    public function new(comp : Component)
    {
        this.comp = comp;
        lasttime = flash.Lib.getTimer();
    }

    public function predict() : Array<Float>
    {
        var curtime = flash.Lib.getTimer();
        var increment = (Math.max(0,(curtime - lasttime)) / 1000) / GameSpeed.secondsperframe;
        return [comp.data[x]+(comp.data[xspeed]*increment),comp.data[y]+(comp.data[yspeed]*increment)];
    }

    public function onUpdate()
    {
        lasttime = flash.Lib.getTimer();
    }

    #end

    public static inline function copy(original : Component, copied : Component)
    {
        var od = original.data;
        copied.data = [od[scene],od[x],od[y],od[xspeed], od[yspeed]];
    }

}